package filecheck;

import java.io.*;

/**
 * Created by lawrence on 2015/8/6.
 */
public class CompandFileContent {
    public static void main(String[] a) {
        BufferedReader fis;
        BufferedWriter bw;
        try {
            fis = new BufferedReader(
                    new InputStreamReader(new FileInputStream(new File("D://wifiCollection.wifi"))));
            File outPutFile = new File("D://wifiCollection_new2.wifi");
            if (!outPutFile.exists()) {
                outPutFile.createNewFile();
            } else {
                outPutFile.delete();
                outPutFile.createNewFile();
            }
            bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outPutFile)));
            String lastLine = "";
            String line = fis.readLine();
            int i = 0;
            String lastString = "";
            while (line != null) {
//                System.out.println(line);
                if (line.contains(" ")) {

//                    lastString = line.substring(line.lastIndexOf(" "));

                    if (!lastString.equals(line.substring(line.lastIndexOf(" ")))) {
                        lastString = line.substring(line.lastIndexOf(" "));
                    }
                } else {
                    bw.write(lastString);
                    bw.write(" value = " + line);
//                        bw.write("\n");
//                        if(lastLine.contains("-")) {
//                            String []  count = lastLine.split("-");
//                    bw.write("   Scan Value =" + ++i);
//                        }
                    bw.write("\n");
//                    lastLine = line.substring(line.indexOf(" "));
                }
                line = fis.readLine();


//                    if (lastLine.equals(line.substring(line.lastIndexOf(" ")))) {
//                        i++;
//                    } else {
////                        System.out.println(lastLine);
//                        bw.write(line.substring(line.lastIndexOf(" ") + 1));
////                        bw.write("\n");
////                        if(lastLine.contains("-")) {
////                            String []  count = lastLine.split("-");
//                        bw.write("   Scan Value =" + ++i);
////                        }
//                        bw.write("\n");
//                        lastLine = line.substring(line.indexOf(" "));
//                        i = 0;
//                    }
//                }


            }
            System.out.println("完事");
            bw.flush();
            bw.close();
            fis.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

